package written.w20240918lixiang.q2;

/**
 * Main
 *
 * @Author : Ruoyu Wang
 * @DateTime : 2024/9/18 09:42
 */

import java.util.Scanner;
import java.util.Arrays;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int[] nums = new int[n];
        for (int i = 0; i < n; i++) {
            nums[i] = in.nextInt();
        }
        Arrays.sort(nums);
        long res = 0;
        int tmp = nums[nums.length - 1];
        for (int i = nums.length - 2; i >= 0; i--) {
            res += (long) tmp * nums[i];
            tmp += nums[i];
        }
        System.out.println(res);
    }
}
